package com.snail.starter.mq.rpc;

import com.snail.starter.mq.feign.LocalMessageFeignInterface;
import com.snail.starter.mq.feign.request.LocalMessageConsumerRequest;
import com.snail.starter.mq.feign.request.LocalMessageRequest;
import com.snail.starter.mq.feign.response.LocalMessageConsumerResponse;
import com.snail.starter.mq.feign.response.LocalMessageProducerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author: snail framework
 * @Date: 2023/7/4 14:02
 * @Version: 1.0.0
 */
@Slf4j
@Component
public class LocalMessageRpc {

    @Resource
    LocalMessageFeignInterface localMessageFeignInterface;

    public Long addByProducer(LocalMessageRequest messageRequest) {
        try {
            return localMessageFeignInterface.addByProducer(messageRequest);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#addByProducer messageRequest:{}", messageRequest);
            return null;
        }
    }

    public boolean modifyStatusByProducerTenantId(Long tenantId, Long messageId, Integer status) {
        try {
            return localMessageFeignInterface.modifyStatusByProducerTenantId(tenantId, messageId, status);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#modifyStatusByProducer messageId:{}, status:{}", messageId, status);
            return false;
        }
    }

    public LocalMessageProducerResponse getOneByMessageIdProducer(Long messageId) {
        if(null == messageId){
            return null;
        }
        try {
            return localMessageFeignInterface.getOneByMessageIdProducer(messageId);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#getOneByMessageIdProducer messageId:{}", messageId);
            return null;
        }
    }

    public Long addByConsumer(LocalMessageConsumerRequest localMessageConsumerRequest) {
        try {
            return localMessageFeignInterface.addByConsumer(localMessageConsumerRequest);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#addByConsumer messageConsumerRequest:{}", localMessageConsumerRequest);
            return null;
        }
    }

    public boolean modifyStatusByConsumerTenantId(Long tenantId, Long consumerMessageId, Integer status) {
        try {
            return localMessageFeignInterface.modifyStatusByConsumerTenantId(tenantId, consumerMessageId, status);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#modifyStatusByConsumer tenantId:{}, consumerMessageId:{}, status:{}", tenantId, consumerMessageId, status);
            return false;
        }
    }

    public LocalMessageConsumerResponse getOneByMessageIdConsumer(Long consumerMessageId) {
        try {
            return localMessageFeignInterface.getOneByMessageIdConsumer(consumerMessageId);
        } catch (Throwable throwable) {
            log.error("", throwable);
            log.error("LocalMessageRpc#getOneByMessageIdConsumer consumerMessageId:{}", consumerMessageId);
            return null;
        }
    }

}